package main

import (
	"fmt"
	"demserver/src/elevation"
)

func main() {
	// Create a GeoTIFF struct with the correct geotransform
	geoTiff := &elevation.GeoTIFF{
		Width:  10000, // Approximate size
		Height: 10000, // Approximate size
	}
	
	// Set the geotransform parameters we parsed from the TFW file
	geoTiff.GeoTransform[0] = 102.33175524278985  // x-coordinate of the center of the upper left pixel
	geoTiff.GeoTransform[1] = 0.000130244367997  // pixel size in the x-direction
	geoTiff.GeoTransform[2] = 0                     // rotation about x-axis
	geoTiff.GeoTransform[3] = 31.768073065845446 // y-coordinate of the center of the upper left pixel
	geoTiff.GeoTransform[4] = 0                     // rotation about y-axis
	geoTiff.GeoTransform[5] = -0.000130250355006 // pixel size in the y-direction
	
	// Test coordinate conversion with your coordinates
	lat := 31.029596331678416
	lon := 103.55108474360813
	x, y, err := geoTiff.LatLonToPixel(lat, lon)
	if err != nil {
		fmt.Printf("Failed to convert coordinates (%f, %f): %v\n", lat, lon, err)
		return
	}
	fmt.Printf("Pixel coordinates for (%f, %f): (%f, %f)\n", lat, lon, x, y)
	
	// Check if coordinates are within bounds (using approximate size)
	if x < 0 || y < 0 || x >= float64(geoTiff.Width) || y >= float64(geoTiff.Height) {
		fmt.Printf("Coordinates out of bounds. Image size: %dx%d\n", geoTiff.Width, geoTiff.Height)
	} else {
		fmt.Printf("Coordinates are within bounds\n")
	}
}
